package com.songtech.store.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.songtech.common.dictionary.dao.SysDictionaryGroupMapper;
import com.songtech.common.dictionary.dao.SysDictionaryMapper;
import com.songtech.store.bean.StoreRecord;
import com.songtech.store.dao.StoreRecordMapper;
import com.songtech.store.service.StoreRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: RENTIE
 * Date: 2018-06-19 11:16
 */
@Service
public class StoreRecordServiceImpl implements StoreRecordService {

    @Resource
    private StoreRecordMapper storeRecordMapper;

    @Resource
    private SysDictionaryGroupMapper sysDictionaryGroupMapper;

    @Resource
    private SysDictionaryMapper sysDictionaryMapper;

    @Override
    public PageInfo<StoreRecord> selectStoreRecord(Map<String,String> map) {
        Integer currentPage = Integer.valueOf(map.get("page"));
        Integer pageSize = Integer.valueOf(map.get("limit"));
        // 分页,禁用合理化，如果pageNum<1或pageNum>pages会返回空数据
        PageHelper.startPage(currentPage, pageSize,true,false);
        List<StoreRecord> list= storeRecordMapper.selectStoreRecord(map);
        if (list!=null){
            list.forEach(l->{
                l.setVender(sysDictionaryGroupMapper.selectNameById(l.getCompanyCode()));
                l.setProduct(sysDictionaryMapper.selectNameById(l.getProductCode()));
                l.setVersion(sysDictionaryMapper.selectNameById(l.getModelNumber()));
                l.setStoreRegionValue(sysDictionaryMapper.selectNameById(l.getStoreRegion()));
            });
        }

        return new PageInfo<StoreRecord>(list);
    }

}
